<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:body>
	<ui:composition template="/WEB-INF/templates/1000_layout.xhtml">

		<ui:define name="head">
			<title>Returns : Withdraw</title>
		</ui:define>
		<ui:define name="clipboard">
		</ui:define>
		<ui:define name="content">
			<br />
			<p:fieldset id="fsMain" legend="Withdraw from Returns">
				<h:form id="withdrawalTableForm">

					<p:panelGrid style="margin-top:20px;width: 100%;">
						<f:facet name="header">
							<p:row>
								<p:column>For Project</p:column>
								<p:column>Description</p:column>
							</p:row>
						</f:facet>
						<p:row>
							<p:column style="width:25%">
								<p:selectOneMenu value="#{dtReturnWithdrawalView.projectId}">
									<f:selectItems var="project"
										value="#{dtReturnWithdrawalView.projects}"
										itemLabel="#{project.code} : #{project.description}"
										itemValue="#{project.id}" />
								</p:selectOneMenu>
							</p:column>
							<p:column style="width:75%">
								<p:inputText style="width:95%" id="description" required="true" requiredMessage="Please provide description."
									value="#{dtReturnWithdrawalView.description}" />
								<br/><p:message for="description" />
							</p:column>
						</p:row>
					</p:panelGrid>
					<br />

					<p:dataTable var="reserve"
						value="#{dtReturnWithdrawalView.reserveList}">
						<p:column headerText="Item#">
							<h:outputText value="#{reserve.itemNumber}" />
						</p:column>
						<p:column headerText="Warehouse">
							<h:outputText value="#{reserve.warehouse.name}" />
						</p:column>
						<p:column headerText="Name">
							<h:outputText value="#{reserve.partUnit.shortName}" />
						</p:column>
						<p:column headerText="Brand">
							<h:outputText value="#{reserve.partUnit.shortBrand}" />
						</p:column>
						<p:column headerText="Part Number">
							<h:outputText value="#{reserve.partUnit.part}" />
						</p:column>
						<p:column headerText="Unit">
							<h:outputText value="#{reserve.partUnit.shortUnit}" />
						</p:column>
						<p:column headerText="Quantity">
							<h:outputText value="#{reserve.quantity}" />
						</p:column>
						<p:column headerText="Action">
							<h:commandButton value="Remove" update="@form :formBalanceTable" immediate="true"
								action="#{dtReturnWithdrawalView.remove(reserve.id)}" />
						</p:column>
					</p:dataTable>
					<br />
					<p:commandButton disabled="#{dtReturnWithdrawalView.requestDisabled}" update="@form"
					    action="#{dtReturnWithdrawalView.withdraw}" 
						value="Request for Withdrawal" />
				</h:form>
			</p:fieldset>
			<br />
			<p:fieldset id="fsAdd" legend="Add" toggleable="true"
				toggleSpeed="500" collapsed="true">
				<h:form id="formBalanceTable">
					<ui:include
						src="/WEB-INF/templates/entity/returnsBalance.table.xhtml">
						<ui:param name="ajaxEventUpdate" value="@form :withdrawDlgForm:returnsDetail" />
						<ui:param name="ajaxEventOnComplete" value="PF('returnsDialog').show();" />
						<ui:param name="quantityMap" value="#{dtReturnWithdrawalView.quantityMap}" />
					</ui:include>
				</h:form>
				<h:form id="withdrawDlgForm">
					<ui:include
						src="/WEB-INF/templates/entity/returnsBalance.withdraw.dialog.xhtml">
						<ui:param name="reserveCommandUpdate" value="@form :withdrawalTableForm :formBalanceTable" />
						<ui:param name="quantityMap" value="#{dtReturnWithdrawalView.quantityMap}" />
					</ui:include>
				</h:form>
			</p:fieldset>

		</ui:define>
	</ui:composition>
</h:body>
</html>